
#include <stdio.h>
#include "lettershell/shell.h"
#include "cmsis_os2.h"
#include "FreeRTOS.h"
#include "task.h"

#include "global.h"



static int do_heap(void)
{
    UBaseType_t task_priority;
    size_t free_size = xPortGetFreeHeapSize();
    size_t min_free_size = xPortGetMinimumEverFreeHeapSize();
    size_t total_size = configTOTAL_HEAP_SIZE;

    task_priority = uxTaskPriorityGet(NULL);
    vTaskPrioritySet(NULL, configMAX_PRIORITIES-1);

    printf(" The heap has total %u bytes.\r\n", total_size);
    printf(" And it has %u free bytes now, %d percent.\r\n", free_size, free_size * 100 / total_size);
    printf(" And it has %u free bytes when it's used the most, %d percent.\r\n\r\n", min_free_size, min_free_size * 100 / total_size);
    // qlsdk_heap_usage_report(); 

    vTaskPrioritySet(NULL, task_priority);
    return SUCC;
}

SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC) | SHELL_CMD_DISABLE_RETURN,
                 heap, do_heap, show the heap info);